<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="Author" content="larry" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="/static/admin/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/common/css/animate.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="larry-container larryms-admin">
        <div class="layui-row layui-col-space20">
            <div class="layui-col-xs12 animated fadeInRightBig">
                <section class="larry-panel">
                    <div class="larryms-page-header">
                        <span class="tit">添加商品</span>
                    </div>
                    <div class="larryms-page-body">
                        <form class="layui-form" enctype="multipart/form-data">
                            <div class="layui-form-item">
                                <label class="layui-form-label">商品标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="goods_name" value="" class="layui-input" required lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">商品分类</label>
                                <div class="layui-input-block">
                                    <select name="cate_id" lay-verify="required">
                                        <option value="">请选择</option>
                                        {volist name="list" id="vo"}
                                        <option value="{$vo.id}">{$vo._name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">商品卖点</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入商品卖点" class="layui-textarea" name="goods_remark" required lay-verify="required"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">缩略图</label>
                                <div class="layui-input-block">
                                    <div>
                                        <input type="text" name="original_img" id="original_img" value="" class="layui-input">
                                    </div><br />
                                    <div class="layui-upload-drag" id="test10">
                                        <i class="layui-icon"></i>
                                        <p>点击上传，或将文件拖拽到此处</p>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">售价</label>
                                <div class="layui-input-block">
                                    <input type="text" name="shop_price" value="" class="layui-input" required lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">商品详情描述</label>
                                <div class="layui-input-block">
                                    <script id="editor" type="text/plain" name="goods_content" required lay-verify="required"></script>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">库存数量</label>
                                <div class="layui-input-block">
                                    <input type="text" name="store_count" value="1000" class="layui-input" required lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">上/下架</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="is_on_sale" lay-skin="switch" lay-text="上架|下架" checked></td>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">下载地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="download_url" value="" class="layui-input" required lay-verify="required"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">下载密码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="url_pwd" value="" class="layui-input" ></div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="goodsAdd" id="goodsAdd">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    <a type="reset" class="layui-btn layui-btn-danger" href="javascript:history.go(-1);">返回</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
<!-- 加载js文件-->
<script type="text/javascript" src="/static/admin/common/layui/layui.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/admin/ue/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/admin/ue/ueditor.all.js"></script>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    ue.ready(function() {
        ue.setHeight(300);
    });
</script>
<script>
    layui.use(['form','upload','jquery','layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload;
        var form = layui.form;
        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: '/admin/goods/uploadPic'
            ,done: function(res, index, upload){
                //假设code=0代表上传成功
                //console.log(res);
                if(res.code == '1'){
                    layer.msg(res.msg, {icon: 6});
                    $('#original_img').val(res.name);
                }else{
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
        form.on("submit(goodsAdd)", function(data){
            $.ajax({
                type:"POST",
                url:"{:url('admin/goods/goodsAdd')}",
                dataType:"JSON",
                data:data.field,
                success:function(res){
                    if(res.code == '1'){
                        layer.msg(res.msg, {icon: 6});
                        //console.log(data.code);
                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
            return false;
        })
    });
</script>
</body>
</html>